package com.lovi.myusercenter.common;

import lombok.Data;

import java.io.Serializable;

/**
 * 通用返回类
 */
@Data
public class BaseResponse<T> implements Serializable {
    /**
     * 状态码，
     * 成功为 0
     */
    private int code;
    /**
     * 数据可以是任何类型，所以设置成泛型
      */
    private T data;
    /**
     * 成功/失败信息
     */
    private String message;
    /**
     * 补充描述信息
     */
    private String description;

    /**
     * 全参
     * @param code
     * @param data
     * @param message
     */
    public BaseResponse(int code, T data, String message,String description) {
        this.code = code;
        this.data = data;
        this.message = message;
        this.description = description;
    }

    public BaseResponse(int code, String message,String description) {
        this(code,null,message,description);
    }

    public BaseResponse(int code, T data,String message) {
        this(code,data,message,null);
    }

    public BaseResponse(int code, T data) {
        this(code,data,null,null);
    }

    public BaseResponse(int code, String message) {
        this(code,null,message,null);
    }

    /**
     * 适用于错误方法的封装
     * @param errorCode
     */
    public BaseResponse(ErrorCode errorCode) {
        this(errorCode.getCode(),errorCode.getMessage());
    }

}
